package LeetDev.a3d;

public class Vect {
	public float x;
	public float y;
	public float z;

	public static final Vect zero=new Vect(0,0,0);
	
	public Vect()
	{
		x=y=z=0;
	}
	
	public Vect(float ix,float iy,float iz)
	{
		x=ix;
		y=iy;
		z=iz;
	}
	
	public Vect(final Vect v)
	{
		x=v.x;
		y=v.y;
		z=v.z;
	}

	public void normalize()
	{
		float sqr=x*x+y*y+z*z;
		if(sqr!=0) 
		{
			float len=(float)(1/Math.sqrt(sqr));
			x*=len;
			y*=len;
			z*=len;
		}
	}
	public void sub(final Vect v, Vect result)
	{
		result.x=x-v.x;
		result.y=y-v.y;
		result.z=z-v.z;
	}
	public void add(final Vect v, Vect result)
	{
		result.x=x+v.x;
		result.y=y+v.y;
		result.z=z+v.z;
	}
	public void cross(final Vect v, Vect result)
	{
		result.x=y*v.z-z*v.y;
		result.y=z*v.x-x*v.z;
		result.z=x*v.y-y*v.x;
	}

	public float dot(final Vect v)
	{
		return(x*v.x+y*v.y+z*v.z);
	}
	
	public float length()
	{
		return((float)Math.sqrt(x*x+y*y+z*z));
	}
	
	public void mul(final float n, Vect result)
	{
		result.x=x*n;
		result.y=y*n;
		result.z=z*n;
	}

	public void div(final float n, Vect result)
	{
		result.x=x/n;
		result.y=y/n;
		result.z=z/n;
	}
}
